$(function () {
    var xsjsdId = $("#fp_xsjsd_id").val();
    if (xsjsdId == "") {
        xsjsdId = 0;
    }

    $("#grid_xsd_fp").edatagrid({
        url: $.webPath() + "/xsgl/xsdgl/xsdmxSearchList?xsjsdId=" + xsjsdId,
        width: 1000,
        height: 275,
        fitColumns: false,
        fit: false,
        singleSelect: true,
        //checkbox: true,
        checkOnSelect: false,
        selectOnCheck: false,
        showFooter: true,
        rownumbers: true,
        frozenColumns: [
            [
                // {field: 'checked', checkbox: true},
                {field: 'xsdh', title: '销售单号', width: 120},
                {field: 'wzgg.code', title: '物资编码', width: 120},
                {field: 'wzgg.name', title: '物资名称', width: 70},
                {field: 'wzgg.ggxh', title: '规格型号', width: 70},
                {field: 'wzgg.dw', title: '单位', width: 50}
            ]
        ],
        columns: [
            [
                {field: 'hsj', title: '含税价(元)', formatter: function (value) {
                    var sl = formatJe2(value, ",");
                    return sl;
                }, width: 120},
                {field: 'bhsj', title: '不含税价(元)', formatter: function (value) {
                    var sl = formatJe2(value, ",");
                    return sl;
                }, width: 120},
                {field: 'ck_sbsl', title: '数量', formatter: function (value) {
                    var sl = formatSl(value, ",");
                    return sl;
                }, width: 100},
                {field: 'je', editor: {type: 'numberbox', options: {precision: 2, min: 0, groupSeparator: ','}}, title: '净额(元)', formatter: function (value) {
                    var sl = formatJe2(value, ",");
                    return sl;
                }, width: 120},
                {field: 'se', editor: {type: 'numberbox', options: {precision: 2, min: 0, groupSeparator: ','}}, title: '税额(元)', formatter: function (value) {
                    var sl = formatJe2(value, ",");
                    return sl;
                }, width: 120},
                {field: 'ce', title: '差额(元)', formatter: function (value) {
                    var sl = formatJe2(value, ",");
                    return sl;
                }, width: 120}
            ]
        ], onSelect: function (rowIndex, rowData) {
            //获取每个单元格
            $("#grid_xsd_fp").edatagrid('editRow', rowIndex);
            var editors = $("#grid_xsd_fp").datagrid('getEditors', rowIndex);
            if (editors.length == 0)
                return;
            var jeEditor = editors[0];
            var seEditor = editors[1];
            jeEditor.target.unbind("change").bind('change', function () {
                $(jeEditor.target).numberbox('setValue', $(jeEditor.target).val());

                var hsj = Math.round(rowData.hsj * 10000) / 10000;
                var sl = Math.round(rowData.ck_sbsl * 10000) / 10000;
                var hse = Math.round(multiply(sl, hsj) * 100) / 100;

                rowData.ce = formatMoney(hse - (parseFloat($(jeEditor.target).numberbox('getValue')) + parseFloat($(seEditor.target).numberbox('getValue'))));
                var data = $("#grid_xsd_fp").edatagrid('getData');
                var ce = 0.0, je = 0.0;
                for (var i = 0; i < data.rows.length; i++) {
                    if (i == rowIndex) {
                        ce += parseFloat(data.rows[i].ce == null ? 0 : data.rows[i].ce);
                        je += parseFloat($(jeEditor.target).numberbox('getValue')== null ? 0 :$(jeEditor.target).numberbox('getValue'));
                    } else {
                        ce += parseFloat(data.rows[i].ce == null ? 0 : data.rows[i].ce);
                        je += parseFloat(data.rows[i].je == null ? 0 : data.rows[i].je);
                    }
                }
                $("#fp_xsjsd_ce").val(formatJeForHtml2(ce));
                $("#fp_xsjsd_je").val(formatJeForHtml2(je));
                $("#fp_xsjsd_me").val(formatJeForHtml2(fpCountMe()));
                $("#fp_fpze").val(formatJeForHtml2(fpCountMe()));
                $("#grid_xsd_fp").edatagrid('saveRow');

            });
            seEditor.target.unbind("change").bind('change', function () {
                $(seEditor.target).numberbox('setValue', $(seEditor.target).val());

                var hsj = Math.round(rowData.hsj * 10000) / 10000;
                var sl = Math.round(rowData.ck_sbsl * 10000) / 10000;
                var hse = Math.round(multiply(sl, hsj) * 100) / 100;

                rowData.ce = formatMoney(hse - (parseFloat($(seEditor.target).numberbox('getValue')) + parseFloat($(jeEditor.target).numberbox('getValue'))));
                var data = $("#grid_xsd_fp").edatagrid('getData');
                var ce = 0.0, se = 0.0;
                for (var i = 0; i < data.rows.length; i++) {
                    if (i == rowIndex) {
                        ce += parseFloat(data.rows[i].ce == null ? 0 : data.rows[i].ce);
                        se += parseFloat($(seEditor.target).numberbox('getValue') == null ? 0: $(seEditor.target).numberbox('getValue'));
                    } else {
                        ce += parseFloat(data.rows[i].ce == null ? 0 : data.rows[i].ce);
                        se += parseFloat(data.rows[i].se==null ? 0 :data.rows[i].se);
                    }
                }

                $("#fp_xsjsd_ce").val(formatJeForHtml2(ce));
                $("#fp_xsjsd_se").val(formatJeForHtml2(se));
                $("#fp_xsjsd_me").val(formatJeForHtml2(fpCountMe()));
                $("#fp_fpze").val(formatJeForHtml2(fpCountMe()));
                $("#grid_xsd_fp").edatagrid('saveRow', rowIndex);
            });
        }
    })

    //物流结算单明细显示
    $.post($.webPath() + '/cwgl/kmys/cyfyys/fylbcombobox', {'gsId': $("[name='fp.gs.id']").val()},function (fsOptions) {
        $("#grid_fp_wld").edatagrid({
            url:$.webPath() + "/jsgl/wljsd/wldSearchList?wljsdId="+xsjsdId,
            fitColumns: true,
            singleSelect: true,
            pagination:true,
            pageSize:100,
            width:1009,
            height:316,
            checkOnSelect: false,
            selectOnCheck: false,
            rownumbers: true,
            columns: [
                [
                    {field:'id', title:'ID', hidden:true},
                    {field:'wljsd.id', title:'物流结算单ID', hidden:true},
                    {field:'cgd.id', title:'采购单ID', hidden:true},
                    {field:'sydw.id', title:'物流商ID', hidden:true},
                    {field:'sydw.qc', title:'物流商', width:40},
                    {field:'jfsl', title:'计费数量', width:25,
                        formatter:function(value){
                            var val = formatSlForHtml(value);
                            return val;
                        }},
                    {field:'dj', title:'单价', width:20,formatter:function(value){
                        var val = formatJeForHtml(value);
                        return val;
                    }},
                    {field:'je', title:'金额', width:20,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field: 'fylb.id', editor: {type: 'combobox', options: {
                        data: fsOptions,
                        valueField: 'id',
                        textField: 'fykmjc',
                        multiple: false,
                        panelHeight: '100'
                    }
                    }, formatter: function (value) {
                        for (var i = 0; i < fsOptions.length; i++) {
                            if (fsOptions[i].id == value) return fsOptions[i].fykmjc;
                        }
                        return value;
                    }, title: '费用类别', width: 30},
                    {field: 'hdsl', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 4}},
                        title: '核定数量', width: 25,formatter:function(value){
                        var val = formatSlForHtml(value);
                        return val;
                    }},
                    {field: 'hddj', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 4}},
                        title: '核定单价', width: 25,formatter:function(value){
                        var val = formatJeForHtml(value);
                        return val;
                    }},
                    {field: 'hdje', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 2}},
                        title: '核定金额', width: 25,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field: 'me', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 2}},
                        title: '面额', width: 20,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field: 'kdse', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 2}},
                        title: '可抵税额', width: 20,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field: 'se', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 2}},
                        title: '税额', width: 20,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field: 'jsje', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 2}},
                        title: '净额', width: 20,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field: 'ce', editor: {type: 'numberbox', options: {groupSeparator: ',', precision: 2}},
                        title: '差额', width: 20,formatter:function(value){
                        var val = formatJeForHtml2(value);
                        return val;
                    }},
                    {field:'bz', title:'备注', width:20}
                ]
            ],
            onSelect: function (rowIndex, rowData) {
                //获取每个单元格
                $("#grid_fp_wld").edatagrid('editRow', rowIndex);
                var editors = $("#grid_fp_wld").edatagrid('getEditors', rowIndex);
                if (editors.length == 0)
                    return;
                var fylbEditor = editors[0];//费用类别编辑框
                var hdslEditor = editors[1];//核定数量编辑框
                var hddjEditor = editors[2];//核定单价编辑框
                var hdjeEditor = editors[3];//核定金额编辑框
                var meEditor = editors[4];//面额编辑框
                var kdseEditor = editors[5];//可抵税额编辑框
                var seEditor = editors[6];//税额编辑框
                var jsjeEditor = editors[7];//净额编辑框
                var ceEditor = editors[8];//差额编辑框

                hdslEditor.target.unbind("blur").bind('blur', function () {
                    setTimeout(function () {
                        $(hdslEditor.target).numberbox('setValue',$(hdslEditor.target).val());
                        $(hddjEditor.target).numberbox('setValue',$(hddjEditor.target).val());
                        $(hdjeEditor.target).numberbox('setValue',$(hdslEditor.target).numberbox('getValue')*$(hddjEditor.target).numberbox('getValue'));
                        $(ceEditor.target).numberbox('setValue',$(hdjeEditor.target).numberbox('getValue') - rowData.je);

                        var data = $("#grid_fp_wld").edatagrid('getData');
                        var wljsd_me = 0.00, wljsd_jsje = 0.00,wljsd_se = 0.00 , wljsd_ce = 0.00;
                        for (var i = 0; i < data.rows.length; i++) {
                            if (i == rowIndex) {
                                wljsd_me += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_jsje += parseFloat($(jsjeEditor.target).numberbox('getValue'));
                                wljsd_se += parseFloat($(seEditor.target).numberbox('getValue'));
                                wljsd_ce += parseFloat($(ceEditor.target).numberbox('getValue'));
                            } else{
                                wljsd_me += parseFloat(data.rows[i].me);
                                wljsd_jsje += parseFloat(data.rows[i].jsje);
                                wljsd_se += parseFloat(data.rows[i].se);
                                wljsd_ce += parseFloat(data.rows[i].ce);
                            }
                        }
                        $("#fp_wljsd_me").val(formatJeForHtml2(wljsd_me));
                        $("#fp_wljsd_je").val(formatJeForHtml2(wljsd_jsje));
                        $("#fp_wljsd_se").val(formatJeForHtml2(wljsd_se));
                        $("#fp_wljsd_ce").val(formatJeForHtml2(wljsd_ce));
                        $("#grid_fp_wld").edatagrid('saveRow');

                        var ce = $(ceEditor.target).numberbox('getValue');
                        var zjbcdRows = $("#grid_zjbcd_fp_wljsd").datagrid('getRows');
                        if(rowData['cgd.id'] != null){
                            $.post($.webPath() + '/cggl/cgdgl/cgdmxByCgdId',{'cgdId':rowData['cgd.id'],'ce':ce},function(data){
                                $.each(data,function(i,obj){
                                    $.each(zjbcdRows,function(r,z){
                                        if (obj['id'] == z['cgdmx.id']) {
                                            $('#grid_zjbcd_fp_wljsd').datagrid('deleteRow',r);
                                            return false;
                                        }
                                    })
                                    if (ce != 0) {
                                        $("#grid_zjbcd_fp_wljsd").edatagrid('appendRow', {
                                            'lb.id': 281,
                                            'lb.z': '费用差异',
                                            'je': formatMoney(obj['je']),
                                            'cgd.id': rowData['cgd.id'],
                                            'cgd.cgdh': obj['cgd.cgdh'],
                                            'wzgg.code': obj['wzgg.code'],
                                            'wzgg.name': obj['wzgg.name'],
                                            'wzgg.ggxh': obj['wzgg.ggxh'],
                                            'wzgg.dw': obj['wzgg.dw'],
                                            'cgdmx.id': obj['id']
                                        });
                                        countSumWljsd();
                                    }
                                });
                            })
                        }
                    },200);
                });

                hddjEditor.target.unbind("blur").bind('blur', function () {
                    setTimeout(function () {
                        $(hdslEditor.target).numberbox('setValue',$(hdslEditor.target).val());
                        $(hddjEditor.target).numberbox('setValue',$(hddjEditor.target).val());
                        $(hdjeEditor.target).numberbox('setValue',$(hdslEditor.target).numberbox('getValue')*$(hddjEditor.target).numberbox('getValue'));
                        $(ceEditor.target).numberbox('setValue',$(hdjeEditor.target).numberbox('getValue') - rowData.je);

                        var data = $("#grid_fp_wld").edatagrid('getData');
                        var wljsd_me = 0.00, wljsd_jsje = 0.00,wljsd_se = 0.00 , wljsd_ce = 0.00;
                        for (var i = 0; i < data.rows.length; i++) {
                            if (i == rowIndex) {
                                wljsd_me += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_jsje += parseFloat($(jsjeEditor.target).numberbox('getValue'));
                                wljsd_se += parseFloat($(seEditor.target).numberbox('getValue'));
                                wljsd_ce += parseFloat($(ceEditor.target).numberbox('getValue'));
                            } else{
                                wljsd_me += parseFloat(data.rows[i].me);
                                wljsd_jsje += parseFloat(data.rows[i].jsje);
                                wljsd_se += parseFloat(data.rows[i].se);
                                wljsd_ce += parseFloat(data.rows[i].ce);
                            }
                        }
                        $("#fp_wljsd_me").val(formatJeForHtml2(wljsd_me));
                        $("#fp_wljsd_je").val(formatJeForHtml2(wljsd_jsje));
                        $("#fp_wljsd_se").val(formatJeForHtml2(wljsd_se));
                        $("#fp_wljsd_ce").val(formatJeForHtml2(wljsd_ce));
                        $("#grid_fp_wld").edatagrid('saveRow');

                        var ce = $(ceEditor.target).numberbox('getValue');
                        var zjbcdRows = $("#grid_zjbcd_fp_wljsd").datagrid('getRows');
                        if(rowData['cgd.id'] != null){
                            $.post($.webPath() + '/cggl/cgdgl/cgdmxByCgdId',{'cgdId':rowData['cgd.id'],'ce':ce},function(data){
                                $.each(data,function(i,obj){
                                    $.each(zjbcdRows,function(r,z){
                                        if (obj['id'] == z['cgdmx.id']) {
                                            $('#grid_zjbcd_fp_wljsd').datagrid('deleteRow',r);
                                            return false;
                                        }
                                    })
                                    if (ce != 0) {
                                        $("#grid_zjbcd_fp_wljsd").edatagrid('appendRow', {
                                            'lb.id': 281,
                                            'lb.z': '费用差异',
                                            'je': formatMoney(obj['je']),
                                            'cgd.id': rowData['cgd.id'],
                                            'cgd.cgdh': obj['cgd.cgdh'],
                                            'wzgg.code': obj['wzgg.code'],
                                            'wzgg.name': obj['wzgg.name'],
                                            'wzgg.ggxh': obj['wzgg.ggxh'],
                                            'wzgg.dw': obj['wzgg.dw'],
                                            'cgdmx.id': obj['id']
                                        });
                                        countSumWljsd();
                                    }
                                });
                            })
                        }
                    },200);
                });

                hdjeEditor.target.unbind("blur").bind('blur', function () {
                    setTimeout(function () {
                        $(hdjeEditor.target).numberbox('setValue',$(hdjeEditor.target).val());
                        $(hdslEditor.target).numberbox('setValue',$(hdslEditor.target).val());
                        $(hddjEditor.target).numberbox('setValue',$(hdjeEditor.target).numberbox('getValue')/$(hdslEditor.target).numberbox('getValue'));
                        $(ceEditor.target).numberbox('setValue',$(hdjeEditor.target).numberbox('getValue') - rowData.je);

                        var data = $("#grid_fp_wld").edatagrid('getData');
                        var wljsd_me = 0.00, wljsd_jsje = 0.00,wljsd_se = 0.00 , wljsd_ce = 0.00;
                        for (var i = 0; i < data.rows.length; i++) {
                            if (i == rowIndex) {
                                wljsd_me += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_jsje += parseFloat($(jsjeEditor.target).numberbox('getValue'));
                                wljsd_se += parseFloat($(seEditor.target).numberbox('getValue'));
                                wljsd_ce += parseFloat($(ceEditor.target).numberbox('getValue'));
                            } else{
                                wljsd_me += parseFloat(data.rows[i].me);
                                wljsd_jsje += parseFloat(data.rows[i].jsje);
                                wljsd_se += parseFloat(data.rows[i].se);
                                wljsd_ce += parseFloat(data.rows[i].ce);
                            }
                        }
                        $("#fp_wljsd_me").val(formatJeForHtml2(wljsd_me));
                        $("#fp_wljsd_je").val(formatJeForHtml2(wljsd_jsje));
                        $("#fp_wljsd_se").val(formatJeForHtml2(wljsd_se));
                        $("#fp_wljsd_ce").val(formatJeForHtml2(wljsd_ce));
                        $("#grid_fp_wld").edatagrid('saveRow');

                        var ce = $(ceEditor.target).numberbox('getValue');
                        var zjbcdRows = $("#grid_zjbcd_fp_wljsd").datagrid('getRows');
                        if(rowData['cgd.id'] != null){
                            $.post($.webPath() + '/cggl/cgdgl/cgdmxByCgdId',{'cgdId':rowData['cgd.id'],'ce':ce},function(data){
                                $.each(data,function(i,obj){
                                    $.each(zjbcdRows,function(r,z){
                                        if (obj['id'] == z['cgdmx.id']) {
                                            $('#grid_zjbcd_fp_wljsd').datagrid('deleteRow',r);
                                            return false;
                                        }
                                    })
                                    if (ce != 0) {
                                        $("#grid_zjbcd_fp_wljsd").edatagrid('appendRow', {
                                            'lb.id': 281,
                                            'lb.z': '费用差异',
                                            'je': formatMoney(obj['je']),
                                            'cgd.id': rowData['cgd.id'],
                                            'cgd.cgdh': obj['cgd.cgdh'],
                                            'wzgg.code': obj['wzgg.code'],
                                            'wzgg.name': obj['wzgg.name'],
                                            'wzgg.ggxh': obj['wzgg.ggxh'],
                                            'wzgg.dw': obj['wzgg.dw'],
                                            'cgdmx.id': obj['id']
                                        });
                                        countSumWljsd();
                                    }
                                });
                            })
                        }
                    },200);
                });

                meEditor.target.unbind("blur").bind('blur', function () {
                    setTimeout(function () {
                        $(meEditor.target).numberbox('setValue',$(meEditor.target).val());
                        $(jsjeEditor.target).numberbox('setValue',$(meEditor.target).numberbox('getValue')-$(seEditor.target).numberbox('getValue'));
                        var data = $("#grid_fp_wld").edatagrid('getData');
                        var wljsd_fpje = 0.00,wljsd_me = 0.00, wljsd_jsje = 0.00,wljsd_se = 0.00 , wljsd_ce = 0.00;
                        for (var i = 0; i < data.rows.length; i++) {
                            if (i == rowIndex) {
                                wljsd_fpje += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_me += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_jsje += parseFloat($(jsjeEditor.target).numberbox('getValue'));
                                wljsd_se += parseFloat($(seEditor.target).numberbox('getValue'));
                                wljsd_ce += parseFloat($(ceEditor.target).numberbox('getValue'));
                            } else{
                                wljsd_fpje += parseFloat(data.rows[i].me);
                                wljsd_me += parseFloat(data.rows[i].me);
                                wljsd_jsje += parseFloat(data.rows[i].jsje);
                                wljsd_se += parseFloat(data.rows[i].se);
                                wljsd_ce += parseFloat(data.rows[i].ce);
                            }
                        }
                        $("#fp_fpze").val(formatJeForHtml2(wljsd_fpje));
                        $("#fp_wljsd_me").val(formatJeForHtml2(wljsd_me));
                        $("#fp_wljsd_je").val(formatJeForHtml2(wljsd_jsje));
                        $("#fp_wljsd_se").val(formatJeForHtml2(wljsd_se));
                        $("#fp_wljsd_ce").val(formatJeForHtml2(wljsd_ce));
                        $("#grid_fp_wld").edatagrid('saveRow');
                    },200);
                });

                kdseEditor.target.unbind("blur").bind('blur', function () {
                    setTimeout(function () {
                        $(kdseEditor.target).numberbox('setValue',$(kdseEditor.target).val());
                        var data = $(fylbEditor.target).combobox("getData");
                        var value = $(fylbEditor.target).combobox("getValue");
                        var kdse = $(kdseEditor.target).numberbox('getValue');
                        var sl = $.grep(data,function(v,i){
                            if (v["id"] == value){
                                $(seEditor.target).numberbox('setValue',kdse*v['sl']/100);
                            }
                        });
                        $(jsjeEditor.target).numberbox('setValue',$(meEditor.target).numberbox('getValue')-$(seEditor.target).numberbox('getValue'));
                        $(ceEditor.target).numberbox('setValue',$(hdjeEditor.target).numberbox('getValue') - rowData.je);

                        var data = $("#grid_fp_wld").edatagrid('getData');
                        var wljsd_me = 0.00, wljsd_jsje = 0.00,wljsd_se = 0.00 , wljsd_ce = 0.00;
                        for (var i = 0; i < data.rows.length; i++) {
                            if (i == rowIndex) {
                                wljsd_me += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_jsje += parseFloat($(jsjeEditor.target).numberbox('getValue'));
                                wljsd_se += parseFloat($(seEditor.target).numberbox('getValue'));
                                wljsd_ce += parseFloat($(ceEditor.target).numberbox('getValue'));
                            } else{
                                wljsd_me += parseFloat(data.rows[i].me);
                                wljsd_jsje += parseFloat(data.rows[i].jsje);
                                wljsd_se += parseFloat(data.rows[i].se);
                                wljsd_ce += parseFloat(data.rows[i].ce);
                            }
                        }
                        $("#fp_wljsd_me").val(formatJeForHtml2(wljsd_me));
                        $("#fp_wljsd_je").val(formatJeForHtml2(wljsd_jsje));
                        $("#fp_wljsd_se").val(formatJeForHtml2(wljsd_se));
                        $("#fp_wljsd_ce").val(formatJeForHtml2(wljsd_ce));
                        $("#grid_fp_wld").edatagrid('saveRow');
                    },200);
                });

                seEditor.target.unbind("blur").bind('blur', function () {
                    setTimeout(function () {
                        $(seEditor.target).numberbox('setValue',$(seEditor.target).val());
                        $(jsjeEditor.target).numberbox('setValue',$(meEditor.target).numberbox('getValue')-$(seEditor.target).numberbox('getValue'));
                        var data = $("#grid_fp_wld").edatagrid('getData');
                        var wljsd_fpje = 0.00,wljsd_me = 0.00, wljsd_jsje = 0.00,wljsd_se = 0.00 , wljsd_ce = 0.00;
                        for (var i = 0; i < data.rows.length; i++) {
                            if (i == rowIndex) {
                                wljsd_fpje += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_me += parseFloat($(meEditor.target).numberbox('getValue'));
                                wljsd_jsje += parseFloat($(jsjeEditor.target).numberbox('getValue'));
                                wljsd_se += parseFloat($(seEditor.target).numberbox('getValue'));
                                wljsd_ce += parseFloat($(ceEditor.target).numberbox('getValue'));
                            } else{
                                wljsd_fpje += parseFloat(data.rows[i].me);
                                wljsd_me += parseFloat(data.rows[i].me);
                                wljsd_jsje += parseFloat(data.rows[i].jsje);
                                wljsd_se += parseFloat(data.rows[i].se);
                                wljsd_ce += parseFloat(data.rows[i].ce);
                            }
                        }
                        $("#fp_fpze").val(formatJeForHtml2(wljsd_fpje));
                        $("#fp_wljsd_me").val(formatJeForHtml2(wljsd_me));
                        $("#fp_wljsd_je").val(formatJeForHtml2(wljsd_jsje));
                        $("#fp_wljsd_se").val(formatJeForHtml2(wljsd_se));
                        $("#fp_wljsd_ce").val(formatJeForHtml2(wljsd_ce));
                        $("#grid_fp_wld").edatagrid('saveRow');
                    },200);
                });
            }
        })
    });

//资金补差单
    $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'zjbclb'}, function () {

        $("#grid_zjbcd_fp_wljsd").edatagrid({
            url: $.webPath() + "/jsgl/zjbcd/zjbcdSearchWlList?wljsdId=" + xsjsdId,
            fitColumns: true,
            singleSelect: true,
            fit: true,
            checkOnSelect: false,
            selectOnCheck: false,
            pagination: true,
            rownumbers: true,
            showFooter: true,
            columns: [
                [
                    {field:'id', title:'ID', hidden:true},
                    {field: 'lb.id', title:'类别ID', hidden:true},
                    {field: 'lb.z', title: '类别', width: 50},
                    {field: 'wzgg.code', title: '物资编码', width: 50},
                    {field: 'wzgg.name', title: '物资名称', width: 40},
                    {field: 'wzgg.ggxh', title: '规格型号', width: 40},
                    {field: 'wzgg.dw', title: '单位', width: 20},
                    {field: 'je', title: '金额(元)', width: 50,
                        formatter: function (value) {
                            var val = formatMoney(value);
                            return val;
                        }
                    },
                    {field:'cgd.id', title:'采购单ID', hidden:true},
                    {field: 'cgd.cgdh', title: '采购单', width: 72}
                ]
            ],
            onSelect: function (rowIndex) {
                //获取每个单元格
                $("#grid_zjbcd_fp_wljsd").edatagrid('editRow', rowIndex);
                var editors = $("#grid_zjbcd_fp_wljsd").datagrid('getEditors', rowIndex);
                if (editors.length == 0)
                    return;
            },
            onLoadSuccess: function () {
                countSumWljsd();
            }
        });
    });

});



function fpCountMe() {
    var je = $('#fp_xsjsd_je').val();
    je = (je.toString()).replace(/,/g, '');
    je = parseFloat(je);
    var se = $('#fp_xsjsd_se').val();
    se = (se.toString()).replace(/,/g, '');
    se = parseFloat(se);
    return se + je;
}

//合计计算
function countSumWljsd() {
    var sumje = 0;
    var data = $("#grid_zjbcd_fp_wljsd").edatagrid("getData");
    for (var i = 0; i < data.rows.length; i++) {
        var je = parseFloat(data.rows[i]["je"]);
        je = isNaN(je) ? 0 : je;
        sumje += je;
    }
    addFooter(sumje);
}

function addFooter(sumje) {
    var footer = null;
    footer = [
        {"lb.z": "合计", "je": formatMoney(sumje)}
    ];
    if (footer != null)
        $("#grid_zjbcd_fp_wljsd").edatagrid('reloadFooter', footer);
}





